//
//  KKAdviceComplainVC.m
//  DoMi
//
//  Created by 康凯 on 2016/12/7.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKAdviceComplainVC.h"
#import "KKComHttp.h"
#import "KKUserInfoDetailM.h"

@interface KKAdviceComplainVC ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *avatar;
@property (weak, nonatomic) IBOutlet UILabel *nickname;
@property (weak, nonatomic) IBOutlet UILabel *company;
@property (weak, nonatomic) IBOutlet UILabel *job;
@property (weak, nonatomic) IBOutlet UITextView *complainContent;
@property (strong,nonatomic) KKUserInfoDetailM *user;

@end

@implementation KKAdviceComplainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"投诉";
    self.complainContent.delegate=self;
    [self getAdviceCommentInfo];
}

-(void)initData{
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:self.user.avatar] placeholderImage:[UIImage imageNamed:@"default_avater"]];
    self.nickname.text=self.user.nickname;
    self.company.text=self.user.company;
    self.job.text=self.user.job;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
#pragma mark textview代理
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if([textView.text isEqualToString:@"请输入投诉内容"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    if(textView.text.length < 1){
        textView.text = @"请输入投诉内容";
        textView.textColor = [UIColor colorWithHexString:@"#797778"];
    }
}
- (IBAction)commitClick:(id)sender {
    if([self.complainContent.text isEqualToString:@"请输入投诉内容"]){
        [self toast:@"请输入投诉内容"];
        return;
    }
    [self commitAdviceComplain];
    
}
#pragma mark 接口--投诉用户信息
-(void)getAdviceCommentInfo{
    [self showDialog];
    [KKComHttp getAdviceComplainInfo:self.consultId success:^(id data) {
        self.user=data;
        [self initData];
        [self dismissDialog];
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}
#pragma mark 接口--提交投诉
-(void)commitAdviceComplain{
    [self showDialog];
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"expertid":self.user.expertid,@"consultid":self.user.consultid,@"content":self.complainContent.text};
    [KKComHttp commitAdviceComplain:params success:^(id data) {
        self.complainContent.text=@"请输入投诉内容";
        [self toast:@"提交成功"];
        [self dismissDialog];
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}
@end
